package a66weding.com.jiehuntong.common.utils.upfile;

import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by admin on 2016/7/20.
 */
public class NewService {
    HttpURLConnection con;
    URL url;

    public void UploadHead(String u,FileInputStream in) {

        //InputStream in;
        byte[] buf = new byte[1024];

        try {

            url = new URL(u);
            con = (HttpURLConnection) url.openConnection();
            con.setConnectTimeout(200000);
            con.setReadTimeout(120000);
            con.setRequestMethod("POST");
            con.setDoOutput(true);
            con.setDoInput(true);

            OutputStream osw = con.getOutputStream();
            while (in.read(buf) != -1) {
                osw.write(buf);
            }
            osw.flush();
            osw.close();
            in.close();
            int code = con.getResponseCode();
            System.out.println("code:" + code);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
